Editor.Shapes.ResourceConnectable = function (u, i) {
	if (i == undefined) {
		i = this;
	}
	Editor.Shapes.Resource.call(this, u, i);

	this.draggerConnector = new Editor.Draggers.Connector();
	this.draggerConnector.init(this);
	this.inProperties = new Array();
}

Editor.Util.inherits(Editor.Shapes.ResourceConnectable, Editor.Shapes.Resource);

Editor.Shapes.ResourceConnectable.prototype.draw = function () {
	Editor.Shapes.ResourceConnectable.superClass_.draw.call(this);
	this.draggerConnector.draw();
	this.draggerConnector.redraw();
	//if (this.impl.getTypeClass() == 'resourceConnectable' || this.impl.getTypeClass() == 'vocabProperty') {
		//this._resize(Editor.CONFIG.RESOURCE_SHAPE_WIDTH - this.getWidth(), Editor.CONFIG.RESOURCE_SHAPE_HEIGHT - this.getHeight());
	//}
}

Editor.Shapes.ResourceConnectable.prototype.addInProperties = function (propUuid) {
	this.inProperties.push(propUuid);
}

Editor.Shapes.ResourceConnectable.prototype.removeInProperties = function (propUuid) {
	var deleted = false;
	for (var i = 0; i < this.inProperties.length; i++) {
		if (!deleted && this.inProperties[i] == propUuid) {
			this.inProperties.splice(i, 1);
			deleted = true;
		}
	}
}

Editor.Shapes.ResourceConnectable.prototype._remove = function () {
	Editor.Shapes.ResourceConnectable.superClass_._remove.call(this);
	this.draggerConnector.remove();
}

Editor.Shapes.ResourceConnectable.prototype.remove = function () {
	var arrProperties = Array();
	for (var i = 0; i < this.inProperties.length; i++) {
		var s = Editor.STATE.SHAPES.get(this.inProperties[i]);
		if (!s.getIsDeleted()) {
			arrProperties.push(this.inProperties[i]);
		}
	}
	var impl = this;
	var arrConnections = new Array();
	var cmd = new JS.Command({
		execute: function () {
			Editor.Shapes.ResourceConnectable.superClass_.remove.call(impl);
			impl.draggerConnector.remove();
			for (var i = 0; i < arrProperties.length; i++) {
				var s = Editor.STATE.SHAPES.get(arrProperties[i]);
				if (!s.getIsDeleted()) {
					s._remove();
					Editor.Util.removeConnections(s.getUuid(),arrConnections);
				}
			}
			Editor.Util.removeConnections(impl.getUuid(),arrConnections);
		},
		undo: function () {
			impl.getImplementation().draw();
			for (var i = 0; i < arrProperties.length; i++) {
				var s = Editor.STATE.SHAPES.get(arrProperties[i]);
				if (s.getIsDeleted()) {
					s.draw();
				}
			}
			Editor.Util.unremoveConnections(arrConnections);
		},
		stack: Editor.STATE.CMDSTACK
	});
	cmd.name = 'remove resource';
	cmd.execute();
}

Editor.Shapes.ResourceConnectable.prototype.resizeInitial = function () {
	this._resize(Editor.CONFIG.RESOURCE_SHAPE_WIDTH - this.getWidth(), Editor.CONFIG.RESOURCE_SHAPE_HEIGHT - this.getHeight());
}

Editor.Shapes.ResourceConnectable.prototype.toFront = function () {
	Editor.Shapes.ResourceConnectable.superClass_.toFront.call(this);
	this.draggerConnector.toFront();
}

Editor.Shapes.ResourceConnectable.prototype.toFrontProperties = function () {
	for (var i = 0; i < this.inProperties.length; i++) {
		var p = Editor.STATE.SHAPES.get(this.inProperties[i]);
	}
}

Editor.Shapes.ResourceConnectable.prototype.moveTo = function (x, y) {
	Editor.Shapes.ResourceConnectable.superClass_.moveTo.call(this, x, y);
}

Editor.Shapes.ResourceConnectable.prototype.translate = function (dx, dy) {
	Editor.Shapes.ResourceConnectable.superClass_._translate.call(this, dx, dy);
	this.draggerConnector.translate(dx, dy);
}

Editor.Shapes.ResourceConnectable.prototype._translate = function (dx, dy) {
	Editor.Shapes.ResourceConnectable.superClass_._translate.call(this, dx, dy);
	this.draggerConnector.translate(dx, dy);
}

Editor.Shapes.ResourceConnectable.prototype._resize = function (dw, dh) {
	Editor.Shapes.ResourceConnectable.superClass_._resize.call(this, dw, dh);
	this.draggerConnector.redraw();
	this.draggerConnector.toFront();
}

Editor.Shapes.ResourceConnectable.prototype.resize = function (dw, dh) {
	Editor.Shapes.ResourceConnectable.superClass_.resize.call(this, dw, dh);
	this.draggerConnector.redraw();
	this.draggerConnector.toFront();
}

// get
Editor.Shapes.ResourceConnectable.prototype.getTypeClass = function () {
	return "resourceConnectable";
}

Editor.Shapes.ResourceConnectable.prototype.getInfo = function () {
	var str = '';
	if (Editor.CONFIG.DEBUG) {
		str = 'Resource Connectable:\n';
		str += '---------------\n';
	}
	str += Editor.Shapes.ResourceConnectable.superClass_.getInfo.call(this);
	return str;
}

Editor.Shapes.ResourceConnectable.prototype.getInProperties = function () {
	return this.inProperties;
}

Editor.Shapes.ResourceConnectable.prototype.toObject = function () {
	return {
		'type': 'resource',
		'resource': Editor.Shapes.ResourceConnectable.superClass_.toObject.call(this)
	}
}

Editor.Shapes.ResourceConnectable.prototype.toObjectResource = function () {
	return Editor.Shapes.ResourceConnectable.superClass_.toObject.call(this);
}

Editor.Shapes.ResourceConnectable.prototype.getDraggerConnector = function () {
	return this.draggerConnector;
}

// event
Editor.Shapes.ResourceConnectable.prototype.mouseover = function () {
	if (!Editor.Util.isDragging()) {
		Editor.Shapes.ResourceConnectable.superClass_.mouseover.call(this.impl);
		this.impl.draggerConnector.mouseover();
	}
}

Editor.Shapes.ResourceConnectable.prototype.mouseout = function () {
	if (!Editor.Util.isDragging()) {
		Editor.Shapes.ResourceConnectable.superClass_.mouseout.call(this.impl);
		this.impl.draggerConnector.mouseout();
	}
}

Editor.Shapes.ResourceConnectable.prototype.mousedown = function (e) {
	if (!Editor.Util.isDragging()) {
		Editor.Shapes.ResourceConnectable.superClass_.mousedown.call(this.impl, e);
	}
}

Editor.Shapes.ResourceConnectable.prototype.click = function () {
	if (!Editor.Util.isDragging()) {
		Editor.Shapes.ResourceConnectable.superClass_.click.call(this.impl);
		this.impl.draggerConnector.toFront();
		this.impl.toFrontProperties();
	}
}

Editor.Shapes.ResourceConnectable.prototype.onmouseup = function () {
	Editor.Shapes.ResourceConnectable.superClass_.onmouseup.call(this.impl);
}

